package duan.util;

import java.lang.reflect.Field;

public class HttpUtil {

    /**
     * 获取get的URL（参数拼接）
     * @param url
     * @param obj
     * @return
     */
    public static String getUrl(String url, Object obj) {
        StringBuilder sb = new StringBuilder().append(url).append("?1=1");
        Field[] fields = obj.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            String fieldName = field.getName();
            String fieldValue = "";
            try {
                Object value = field.get(obj);
                if (value != null) {
                    fieldValue = value.toString();
                }
            } catch (Exception e) {
                //
            }
            sb.append("&").append(fieldName).append("=").append(fieldValue);
        }
        return sb.toString();
    }
}
